<template>
    <div class="container">
        <div>
            <div class="filter-order">
                <div class="order-container">
                    <div class="order-item" :class="{ active: isChecked === 1 }" @click="changeOrder(1)">综合榜</div>
                    <div class="order-item" :class="{ active: isChecked === 2 }" @click="changeOrder(2)">热练榜</div>
                    <div class="order-item" :class="{ active: isChecked === 3 }" @click="changeOrder(3)">新锐榜</div>
                    <div class="order-item" :class="{ active: isChecked === 4 }" @click="changeOrder(4)">最新</div>
                </div>
                <div class="filter-btn" @click="showFilter">
                    筛选
                    <svg
                        data-v-04a2d2fe=""
                        aria-hidden="true"
                        class="icon"
                        style="vertical-align: middle; width: 16px; height: 16px; margin-left: 5px"
                    >
                        <use xlink:href="#icon-home_slideup1"></use>
                    </svg>
                </div>
            </div>
            <div class="filter-container" style="display: none">
                <div style="" class="filter-content-container">
                    <div class="filter-row el-row" v-for="labels in filterData.content" :key="labels.label">
                        <div class="filter-label el-col el-col-2">{{ labels.label }}：</div>
                        <div class="filter-content el-col el-col-22">
                            <div class="select-item" v-for="item in labels.choises" :key="item.id">{{ item.name }}</div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <OriginalList :loading="loading" :isChecked="isChecked"></OriginalList>
    </div>
</template>

<script lang="ts">
import { defineComponent } from "vue";

export default defineComponent({
    name: "Original",
});
</script>

<script setup lang="ts">
import { onMounted, ref } from "vue";
import { useOriginalDataStore } from "@/store/modules/index/original";
import { storeToRefs } from "pinia";
import OriginalList from "./components/OriginalList.vue";

/*
 * @description: 分类
 * */
const OriginalDataStore = useOriginalDataStore();
const { getIntegratedDataAsync, getHotDataAsync, getNewDataAsync, getLatestDataAsync, getFilterDataAsync } =
    OriginalDataStore;
const { filterData, integratedData } = storeToRefs(OriginalDataStore);
const isChecked = ref(1);
const changeOrder = (index: number) => {
    isChecked.value = index;
    integratedData.value = [];
    if (index === 1) {
        // 获取综合排序数据
        getIntegratedDataAsync(0).then(() => {
            setTimeout(() => {
                loading.value = false;
            }, 2000);
        });
    }
    if (index === 2) {
        // 获取热练排序数据
        getHotDataAsync(0).then(() => {
            setTimeout(() => {
                loading.value = false;
            }, 2000);
        });
    }
    if (index === 3) {
        // 获取新锐排序数据
        getNewDataAsync(0).then(() => {
            setTimeout(() => {
                loading.value = false;
            }, 2000);
        });
    }
    if (index === 4) {
        // 获取最新排序数据
        getLatestDataAsync(0).then(() => {
            setTimeout(() => {
                loading.value = false;
            }, 2000);
        });
    }
};
onMounted(() => {
    getIntegratedDataAsync(0).then(() => {
        setTimeout(() => {
            loading.value = false;
        }, 2000);
    });
    getFilterDataAsync();
});

// loading加载
let loading = ref(true);

const showFilter = () => {
    const filterContainer: any = document.querySelector(".filter-container");
    const filterContentContainer: any = document.querySelector(".filter-content-container");
    if (filterContainer && filterContentContainer) {
        if (filterContainer.style.display === "none") {
            filterContainer.style.display = "block";
            filterContentContainer.style.height = "auto";
        } else {
            filterContainer.style.display = "none";
            filterContentContainer.style.height = "0";
        }
    }
};
</script>
<style scoped lang="less">
p {
    display: block;
    margin-block-start: 1em;
    margin-block-end: 1em;
    margin-inline-start: 0;
    margin-inline-end: 0;
}

.fold {
    height: 133px;
}

.active {
    color: #f93684 !important;
}

.filter-order {
    display: flex;
    align-items: center;
}

.filter-btn {
    height: 36px;
    border-radius: 18px;
    background: #e9ecec;
    line-height: 36px;
    color: #7d8090;
    font-size: 16px;
    cursor: pointer;
    padding-left: 20px;
    padding-right: 10px;
}

.filter-container {
    padding: 26px 30px;
    border-radius: 4px;
    margin-bottom: 10px;
    position: relative;

    .filter-content-container {
        overflow: hidden;

        .filter-row {
            font-size: 14px;
            margin: 0 0 16px;
            display: flex;

            .filter-label {
                color: #b1b5c1;
                padding: 7px 0;
                width: 120px;
            }

            .filter-content {
                .select-item {
                    display: inline-block;
                    cursor: pointer;
                    font-size: 14px;
                    border-radius: 4px;
                    color: #7d8090;
                    padding: 7px 13px;
                    user-select: none;
                    margin-right: 24px;
                    margin-bottom: 10px;
                }
            }
        }
    }

    .fold-toggle-container {
        text-align: center;
        color: #f93684;
        font-size: 14px;
        margin: 20px 0 0;
        cursor: pointer;
    }
}

.order-container {
    padding: 25px 30px;
    border-radius: 4px;
    margin-bottom: 10px;
    flex: 1;

    .order-item {
        display: inline-block;
        font-size: 14px;
        color: #7d8090;
        cursor: pointer;

        &.menu-hover-container {
            position: relative;

            .menu-content {
                display: none;
                position: absolute;
                z-index: 10020;
                top: 0;
                left: 50%;
                transform: translate(-50%, -17px);
                box-shadow: 2px 0 9px rgb(0 0 0 / 10%);
                border-radius: 4px;
                background-color: #fff;

                .menu-item {
                    padding: 17px 0;
                    width: 120px;
                    text-align: center;
                    font-size: 14px;
                    color: #111;
                    cursor: pointer;

                    &:hover {
                        color: deeppink;
                    }
                }
            }

            &:hover {
                .menu-content {
                    display: block;
                }
            }
        }
    }

    // 除了第一个,后几个左边距为60px
    .order-item:not(:first-child) {
        margin-left: 60px;
    }
}
</style>
